#include "mybutton.h"

MyButton::MyButton(QWidget *parent) : QPushButton(parent)
{

}

void MyButton::setImage(QString normal, QString hover, QString pressed)
{
    this->normal=normal;
    this->hover=hover;
    this->pressed=pressed;
    m_pixmap.load(this->normal);
    update();
}

void MyButton::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        m_pixmap.load(this->pressed);
        update();
        emit clicked();
    }
    QPushButton::mousePressEvent(event);

}

void MyButton::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        m_pixmap.load(this->normal);
        update();
    }
}

void MyButton::enterEvent(QEvent *event)
{
    m_pixmap.load(this->hover);
    update();
}

void MyButton::leaveEvent(QEvent *ev)
{
    m_pixmap.load(this->normal );
    update();
}

void MyButton::paintEvent(QPaintEvent *ev)
{
    QPainter p(this);
    p.drawPixmap(rect(),this->m_pixmap);
}
